<template>
	<view class="content">
		<!-- <view class="top">
			<view class="top_bg">
				<image src="https://img.jinghushi.com/images/0/2025/10/KjB9SKR84E4kEJB9K91f33Rr9k3E3r.png" ></image>
			</view>
			<view class="tit" :class="{'isScroll':isScroll}">
				<view class="t_image">
					<image class="group_tit" src="https://img.jinghushi.com/images/9/2025/10/A7B33uaFUFIxiCefvF1EcRf3B71bFI.png" mode="heightFix"></image>
				</view>
			</view>
		</view> -->
		<view class="Jc_swiper_box">
			<swiper class="Jc_swiper" :autoplay="true" :circular="true" :interval="5000" :indicator-dots="false">
				<swiper-item class="Jc_swiper_item" v-for="item,idx in banner" :key=idx @click="$navTo(item.url)">
					<image class="Jc_swiper_image" :src="item.image" />
				</swiper-item>
			</swiper>
		</view>
		<view class="list_box">
			<view class="l_tit" :class="{'isTitScroll':isTitScroll}">
				<view class="main_tit" :class="{'main_tit_ac':activityTab==item.type}" v-for="item,i in titList"
					@click="changTitTab(item.type)" :key="item.type">
					<text>{{item.name}}</text>
				</view>
			</view>
			<view class="goods_list">
				<view class="gl_box " v-for="item,i in list">
					<view class="flex_align_center">
						<view class="left">
							<image class="l_thumb" :src="item.pt_park_info.image"></image>
							<!-- <image v-if="i==1&&!activityTab" class="l_in" src="https://img.jinghushi.com/images/0/2025/10/bQz9JZ8XOQ49Z3cTkQKwmWt9McTCqq.png" mode="widthFix"></image> -->
						</view>
						<view class="flex1 right" :class="{'flex_col':activityTab}">
							<view class="r_info">
								<view class="g_tit">
									{{item.pt_park_info.name}}
								</view>
								<view class="show_num" v-if="!activityTab">
									<view class="num">
										{{item.pt_park_info.success_num}}人成团
									</view>
									<view class="group_now">
										<image
											src="https://img.jinghushi.com/images/0/2025/10/LL4pwEl40w4BBVUWW44w4wyW4yw41w.png">
										</image>
										<text>还差 {{item.remain_num}} 人拼成</text>
									</view>
								</view>
								<block v-if="activityTab">
									<view class="b_bar" v-if="activityTab==1">
										成团要求：<text class="b_t1">{{item.pt_park_info.success_num}} 人</text>
									</view>
									<view class="b_bar" v-if="activityTab==1">
										成团进度：<text class="b_t2">当前 {{item.join_num}} 人</text>
									</view>
									<view class="b_bar" :class="{'b_bar2':activityTab==2||activityTab==3}">当前状态：
										<text v-if="item.member_status==1&&item.status==1" class="b_status">拼团中</text>
										<text v-if="item.member_status==1&&item.status==3" class="b_status">等待开团</text>
										<text v-if="item.member_status==3" class="b_status b_status_gray">未拼中</text>
										<text v-if="item.member_status==2" class="b_status b_status_purple">已拼中</text>
									</view>
								</block>
							</view>
							<view class="flex_between g_ru_box">
								<view class="g_rule" @click="openRule(item.pt_park_info.pt_rules)">点此查看当前成团规则</view>
								<view class="g_price" v-if="activityTab"><text>￥</text>{{item.pt_park_info.price}}
								</view>
							</view>
							<view class="list_bottom flex_between" v-if="!activityTab">
								<view class="price">
									<text class="p_logo">￥</text>{{item.pt_park_info.price}}
								</view>
								<view class="btn">
									<view class="b_box" @click="joinGroupSumbit(item)">
										<image class="b_bg"
											src="https://img.jinghushi.com/images/0/2025/10/qNPxj7hPqh4XAX4747y762T4A7Ly48.png">
										</image>
										<view class="none_group flex_center">立即购买 <image
												src="https://img.jinghushi.com/images/0/2025/10/Jd54fhPz4X7k7FSTT7444PtDWW44rS.png"
												mode="widthFix"></image>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
					<view class="b_btns" v-if="activityTab">
						<!-- #ifdef MP-WEIXIN -->
						<view class="b_btn" v-if="item.member_status==1&&item.status==1" @click="shareItems(item)">邀请好友参团
						</view>
						<!-- #endif -->
						<!-- #ifdef H5 -->
						<view class="b_btn" v-if="item.member_status==1&&item.status==1" @click="getPoster(item)">邀请好友参团
						</view>
						<!-- #endif -->
						<!-- <view class="b_btn" v-if="item.member_status==3&&item.status==2" @click="shareItem(item)">邀请好友参团
						</view> -->
						<block v-if="item.member_status==3">
							<view class="b_btn" @click="$navTo('/pages/order/detailsx?id='+item.orderid+'&barIdx1=2')">
								已退款，查看订单详情</view>
							<!-- <view class="b_btn" @click="shareItem(item)">
									已退款，查看订单详情</view> -->
							<view class="b_btn b_btn_gray" v-if="item.redpack_status==2">领取红包</view>
							<view class="b_btn b_btn_red" @click="receiveRedpack(item.id,i)"
								v-if="item.redpack_status==1">领取红包</view>
						</block>
						<view class="b_btn" v-if="item.member_status==2"
							@click="$navTo('/pages/order/detailsx?id='+item.orderid+'&barIdx1=2')">查看订单详情</view>
					</view>
				</view>
			</view>
			<view class="empty_loading2">
				<image v-if="isloading" src="/static/business/loading.gif"></image>
				<view v-if="isempty">———— <text>没有更多了</text> ————</view>
			</view>
		</view>
		<shareMenu ref="shareMenu" />
		<uni-popup ref="rulePopup" type="bottom">
			<view class="rulePopup">
				<image class="rule_image"
					src="https://img.jinghushi.com/images/9/2025/10/Xbdesr1374CT2ie23z2E33BceQBE3E.png" ></image>
				<scroll-view class="b_rule_con" scroll-y="true">
					<jyf-parser :html="rule" :selectable="true"></jyf-parser>
				</scroll-view>
			</view>
		
		</uni-popup>
		<!-- #ifdef H5 -->
		<view class="sharebg" v-if="posterImg!=''" @tap="removeimg">
			<image @longtap="toSave" :src="posterImg" mode="widthFix"></image>
		</view>
		<!-- #endif -->
		<red-bao ref="redBao" />
	</view>
</template>

<script>
	import shareMenu from './components/share-menu.vue';
	import redBao from './components/red-bao.vue';
	import {throttle} from 'lodash'
	export default {
		components: {
			shareMenu,
			redBao
		},
		data() {
			return {
				isScroll: false,
				isTitScroll: false,
				titList: [{
						name: '进行中',
						type: 0
					},
					{
						name: '已购',
						type: 1
					},
					{
						name: '未拼中',
						type: 3
					},
					{
						name: '已拼中',
						type: 2
					}
				],
				activityTab: 0,
				isloading: false,
				isempty: false,
				list: [],
				page: 0,
				shareInfo: {},
				rule: '',
				banner: [], //轮播图
				mid: '',
				code: '',
				posterImg: ''
			}
		},
		onPageScroll(e) {
			this.isScroll = e.scrollTop > 0
			this.isTitScroll = e.scrollTop > 175
		},
		onLoad(option) {
			if (option.mid) {
				this.mid = option.mid;
			}
			if (option.code) {
				this.code = option.code;
			}
			if (option.scene) {
				this.mid = option.scene;
			}
			uni.setStorageSync('mid', this.mid)
			if (!uni.getStorageSync('token')) {
				// this.getToken();
			}
			this.init()
		},
		onReachBottom() {
			this.getList();
		},
		onTabItemTap() {
			this.init()
		},
		async onShareAppMessage() {
			return {
				title: this.shareInfo.title,
				path: this.shareInfo.url,
				imageUrl: this.shareInfo.imgurl
			}
		},
		methods: {
			init:throttle(function(){
				this.page = 0;
				this.list = [];
				this.getIndex()
				this.getList();
			},500, {
				leading: true,
				trailing: false
			}),
			getToken() {
				// #ifdef MP-WEIXIN
				uni.login({
					provider: 'weixin',
					success: res => {
						this.$axios('login/autologin', 'POST', 'member', {
							mid: this.mid,
							code: res.code,
							aid: '9184'
						}).then(res => {
							if (res.data.code == 200) {
								uni.setStorageSync('token', res.data.data);
							}
						})
					}
				})
				// #endif
				// #ifdef H5
				this.$axios('login/autoGzlogin', 'POST', 'member', {
					mid: this.mid,
					code: this.code,
				}).then(res => {
					if (res.data.code == 300001) {
						window.location.href = res.data.data
					} else if (res.data.code == 200) {
						uni.setStorageSync('token', res.data.data);
					}
				})
				// #endif
			},
			// 获取轮播图
			getIndex() {
				this.$axios('Group/getIndex', 'POST', 'pt').then(res => {
					if (res.data.code === 200) {
						this.banner = res.data.data.banner_list
					}
				})
			},
			// 领取红包
			receiveRedpack(id, idx) {
				this.$axios('Group/receiveRedpack', 'POST', 'pt', {
					pt_id: id
				}, 1).then(res => {
					if (res.data.code == 200) {
						this.$refs.redBao.open({
							content: res.data.data.msg
						})
						this.list[idx].redpack_status = 2;
					}
				})
			},
			// 立即购买
			joinGroupSumbit(item) {
				uni.removeStorageSync('mid')
				this.$navTo(`/pages/blindBox/createOrder?type=2&id=${item.pt_park_info.goodsid}&pt_id=${item.id}`)
			},
			// H5生成海报
			getPoster(item) {
				uni.showLoading({
					title:'请稍后'
				})
				this.$axios('Detail/create_goods_poster', 'POST', 'pt', {
					goodsid: item.pt_park_info.goodsid,
					url: `/pages/blindBox/createOrder?type=2&id=${item.pt_park_info.goodsid}&pt_id=${item.id}`
				}).then(res => {
					uni.hideLoading();
					if (res.data.code == 200) {
						this.posterImg = res.data.data.url
					}else{
						uni.showModal({
							title:'温馨提示',
							content:res.data.data
						})
					}
				})
			},
			removeimg: function() {
				this.posterImg = ''
			},
			// 长按保存图片
			toSave() {
				var that = this;
				uni.showModal({
					title: '图片保存',
					content: '确定要保存图片吗',
					success: e => {
						if (e['confirm']) {
							that.saveImg(that.posterImg)
						}
					}
				});
			},
			shareItems(e) {
				uni.showLoading({
					title: '请稍候'
				})
				let title = '消费享补贴，就用多米街';
				if (e) {
					this.$axios('WxInfo/getConfig', 'POST', 'shop', {
						url: `/pages/blindBox/createOrder?type=2&id=${e.pt_park_info.goodsid}&pt_id=${e.id}`,
					}).then(res => {
						uni.hideLoading()
						if (res.data.code == 200) {
							this.shareInfo = {
								title: e.pt_park_info.name,
								imgurl: e.pt_park_info.image,
								url: res.data.data.shareinfo.url
							}
							this.$refs.shareMenu.open(e)
						}
					})
				}
			},
			changTitTab(i) {
				if (i == this.activityTab) return;
				this.activityTab = i;
				this.page = 0;
				this.list = [];
				this.isloading = false;
				this.isempty = false;
				this.getList();
			},
			getList() {
				this.page++;
				this.isloading = true;
				this.isempty = false;
				let url;
				if (!this.activityTab) {
					url = 'Group/groupSearch';
				} else {
					url = 'Group/myGroup';
				}
				const id = this.activityTab;
				this.$axios(url, 'POST', 'pt', {
					page: this.page,
					type: this.activityTab,
					psize: 10
				}).then(res => {
					this.isloading = false;
					if (id != this.activityTab) {
						return;
					}
					if (res.data.code == 200) {
						this.list = [...this.list, ...res.data.data.list];
						this.isempty = res.data.data.list.length <= 0;
					}
				})
			},
			openRule(data) {
				this.rule = data;
				this.$refs.rulePopup.open()
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fdf8ff;
	}

	.Jc_swiper_box {
		width: 100%;
		height: 350rpx;
		padding: 0 20rpx;

		.Jc_swiper {
			width: 100%;
			height: 350rpx;
		}

		.Jc_swiper_item {
			width: 100%;
			height: 350rpx;
		}

		.Jc_swiper_image {
			width: 100%;
			height: 350rpx;
			border-radius: 16rpx;
		}
	}

	.list_box {
		position: relative;
		// top: -36rpx;
		border-radius: 30rpx 30rpx 0 0;
		background-color: #fdf8ff;
		z-index: 8;
		overflow: hidden;
		padding-bottom: 160rpx;

		.l_tit {
			width: 100%;
			display: flex;
			justify-content: space-around;
			width: 694rpx;
			padding: 24rpx 0;
			margin: 0 auto;
			// background: #FDF8FF;

			.main_tit {
				display: inline-block;
				position: relative;

				text {
					font-weight: bold;
					color: #13001E;
					font-size: 28rpx;
				}
			}

			.main_tit_ac {
				&::after {
					content: "";
					display: block;
					position: absolute;
					left: 0;
					right: 0;
					margin: auto;
					bottom: -2rpx;
					width: 100%;
					height: 12rpx;
					background: linear-gradient(90deg, #B62BF0 0%, #8813E2 100%);
					opacity: .8;
					z-index: -1;
				}
			}
		}

		.isTitScroll {
			position: fixed;
			// top: 90px;
			top: 0;
			/* #ifdef H5 */
			top: calc(var(--window-top));
			/* #endif */
			z-index: 98;
			width: 100%;
			justify-content: space-evenly;
			background: #FDF8FF;
			/* 提高层级，避免被遮挡 */
		}

		.goods_list {
			padding: 0 20rpx;

			.flex_col {
				display: flex;
				flex-direction: column;
				height: 212rpx;
				justify-content: space-between;
			}

			.right {
				padding-left: 20rpx;

				.list_bottom {
					align-items: center;
					background: #faf4fd;
					border-radius: 16rpx;
					overflow: hidden;

					.price {
						color: #9A1FE8;
						font-size: 32rpx;
						font-weight: bold;
						flex: 1;
						text-align: center;

						.p_logo {
							font-size: 20rpx;
							font-weight: normal;
						}
					}

					.btn {

						.b_box {
							width: 260rpx;
							height: 60rpx;
							position: relative;

							.b_bg {
								position: absolute;
								width: 100%;
								height: 100%;
							}

							.none_group {
								position: absolute;
								width: 210rpx;
								height: 60rpx;
								right: 0;
								top: 0;
								font-weight: bold;
								font-size: 24rpx;
								color: #FFFFFF;

								image {
									width: 14rpx;
									margin-left: 20rpx;
									position: static;
								}
							}
						}
					}

					.btn2 {
						width: 176rpx;
						height: 60rpx;
						line-height: 60rpx;
						text-align: center;
						background: #9A1FE8;
						border-radius: 144rpx;
						color: #FFFFFF;
						font-weight: bold;
					}
				}

				.show_num {
					color: #9A1FE8;
					margin-top: 15rpx;
					display: flex;
					align-items: center;

					.num {
						font-size: 24rpx;
						font-weight: bold;
						color: #FFFFFF;
						background: linear-gradient(90deg, #B62BF0 0%, #8813E2 100%);
						height: 36rpx;
						border-radius: 8rpx;
						margin-right: 10rpx;
						text-align: center;
						line-height: 36rpx;
						padding: 0 12rpx;
					}

					.group_now {
						display: flex;
						align-items: center;

						image {
							width: 120rpx;
							height: 36rpx;
							z-index: 97;
						}

						text {
							background-color: #f5e9fd;
							font-size: 20rpx;
							height: 36rpx;
							line-height: 36rpx;
							padding: 0 20rpx;
							border-radius: 8rpx;
							margin-left: -20rpx;
						}
					}
				}

				.b_bar {
					color: #999999;
					font-size: 24rpx;
					line-height: 44rpx;

					.b_t1 {
						color: #5B5B5B;
					}

					.b_t2 {
						color: #9A1FE8;
						font-weight: bold;
					}

					.b_status {
						background: rgba(154, 31, 232, 0.15);
						line-height: 34rpx;
						padding: 0 10rpx;
						border-radius: 8rpx;
						color: #9A1FE8;
						font-weight: bold;
					}

					.b_status_purple {
						background: #9A1FE8;
						color: #fff;
					}

					.b_status_gray {
						background: rgba(153, 153, 153, 0.15);
						color: #999999;
					}
				}

				.b_bar2 {
					font-size: 28rpx;
					padding-top: 12rpx;
				}

				.g_tit {
					width: 100%;
					color: #13001E;
					font-size: 28rpx;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					/* 限制显示的行数 */
					-webkit-box-orient: vertical;
					overflow: hidden;
				}
			}

			.g_ru_box {
				.g_price {
					color: #9A1FE8;
					font-size: 32rpx;
					font-weight: bold;

					text {
						font-size: 24rpx;
						font-weight: normal;
					}
				}
			}

			.g_rule {
				font-size: 24rpx;
				color: #9A1FE8;
				text-decoration: underline;
				margin: 14rpx 0;
			}

			.gl_box {
				border-radius: 24rpx;
				background: #FFFFFF;
				padding: 10rpx 20rpx;
				width: 100%;
				margin-bottom: 20rpx;

				.left {
					position: relative;
					border: 4rpx solid transparent;
					border-radius: 8rpx;

					.l_thumb {
						width: 212rpx;
						height: 212rpx;
						border-radius: 16rpx;
					}

					.l_in {
						position: absolute;
						left: 0;
						right: 0;
						top: 0;
						margin: auto;
						width: 140rpx;
					}
				}

				.left_ac {
					border: 4rpx solid #9A1FE8;
				}
			}

			.b_btns {
				border-top: 0.4px dashed #f2f1f3;
				margin-top: 20rpx;
				padding-top: 30rpx;
				padding-bottom: 6rpx;
				display: flex;
				justify-content: space-between;

				.b_btn {
					background: #9A1FE8;
					flex: 1;
					margin: 0 6rpx;
					line-height: 72rpx;
					border-radius: 144rpx;
					color: #FFFFFF;
					font-size: 28rpx;
					font-weight: bold;
					text-align: center;
					// box-shadow:  inset -6px -8px 10px 0px rgba(83, 28, 118, 0.5), inset 6px 8px 4px 0px rgba(255, 255, 255, 0.2)
				}

				.b_btn_red {
					background: #EA0000;
					// box-shadow: inset -6px -8px 10px 0px rgba(134,17,50,0.5), inset 6px 8px 4px 0px rgba(234,224,224,0.2);
				}

				.b_btn_gray {
					background: #999999;
					// box-shadow: inset -6px -8px 10px 0px rgba(140,137,137,1), inset 6px 8px 4px 0px rgba(255, 255, 255, 0.2);
				}
			}
		}
	}

	.top {
		.top_bg {
			height: 450rpx;
			width: 100%;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.tit {
			position: absolute;
			// height: 90px;
			top: 0;
			left: 0;
			width: 100%;
			display: flex;
			flex-direction: column;
			justify-content: flex-end;
			padding: 0 30rpx;
			padding-top: calc(var(--status-bar-height) + 50rpx);
			padding-bottom: 0;

			.t_image {
				display: flex;
				align-items: center;

			}

			.group_tit {
				height: 60rpx;
			}
		}
	}

	.tit.isScroll {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		/* 确保宽度满屏 */
		height: 90px;
		background-color: yellow;
		z-index: 98;
		/* 提高层级，避免被遮挡 */
		// padding: 0 30rpx;
		padding-bottom: 10px;
		/* 调整内边距 */
		box-sizing: border-box;
		/* 确保宽度包含内边距 */
		background: linear-gradient(180deg, #9A1FE8 0%, #FFFFFF 100%);
		border-bottom: 2px solid #CCCACD;
	}

	.b_rule_con {
		width: 660rpx;
		height: 800rpx;
		background: #fff;
		border-radius: 16rpx;
		padding: 20rpx;
	}

	.sharebg {
		position: fixed;
		z-index: 998;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, 0.3);

		image {
			width: 80%;
			position: fixed;
			left: 50%;
			top: 50%;
			z-index: 999;
			transform: translate(-50%, -50%);
		}
	}
	.rulePopup {
		width: 100%;
		height: 1000rpx;
		background: linear-gradient(0deg, #FFFFFF 0%, rgba(255, 255, 255, 0) 100%), linear-gradient(90deg, #FDDFFF 0%, #FFE8DB 100%), #FFFFFF;
		position: absolute;
		bottom: calc(var(--window-bottom) - 38px);
		padding: 20rpx;
		border-radius: 24rpx 24rpx 0px 0px;
	}
	.rule_image {
		width: 220rpx;
		height: 68rpx;
		margin-left: calc(50% - 220rpx/2);
	}
	
	.b_rule_con {
		width: 100%;
		height: calc(100% - 80rpx);
		background-color: #fff;
		border-radius: 24rpx;
		padding: 20rpx;
	}
	
	.sharebg {
		position: fixed;
		z-index: 998;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, 0.3);
	
		image {
			width: 80%;
			position: fixed;
			left: 50%;
			top: 50%;
			z-index: 999;
			transform: translate(-50%, -50%);
		}
	}
</style>